package com.globallogic.draw;

public class Trapezium extends DrawObject implements Drawable {

	
	public Trapezium (int shortBase, int longBase, int height) {

		if ((shortBase <= 0) || (longBase <= 0) || (height <= 0))  {
			
			throw new IllegalArgumentException();
			
		}
		
		this.shortBase = shortBase;
		this.longBase = longBase;
		this.height = height;

		this.drawChar = 't';
	}
	
	@Override
	public float calculateSquare() {
		
		return ((shortBase + longBase)*height)/2;
	
	}

	@Override
	public boolean isPointInside(int x, int y) {

		float xLeft;
		float xRight;
		
		if ((y > height) || (y < 0)) {
			
			return false;
			
		}
		
		xLeft = ((longBase - shortBase)*y)/(2*height);
		xRight = (shortBase - longBase)/(2*height) + longBase;
		
		if ((x < xLeft) || (x > xRight)) {
		    
			return false;
		
		}
		
		return true;
	}

	@Override
	public int getLenght() {

		return longBase;
		
	}

	@Override
	public String toString() {
		
		return this.getClass().getSimpleName();
		
	}
	
	
	private int shortBase;
	private int longBase;
    private int height;
	

}
